package com.ideaction.game.rule;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RuleManager {

	private static Map<Integer, List<IRule>> ruleMap = new HashMap<>();

	public static boolean match(int ruleFuncId, RuleInfo ruleInfo) {
		List<IRule> ruleList = ruleMap.get(ruleFuncId);
		for (IRule rule : ruleList) {
			if (!rule.match(ruleInfo)) {
				return false;
			}
		}
		return true;
	}

	public static void regist(int funcId, IRule rule) {
		List<IRule> ruleList = ruleMap.computeIfAbsent(funcId, (key) -> new ArrayList<IRule>());
		ruleList.add(rule);
		log.info("注册rule  funcId:" + funcId + " rule:" + rule);
	}
}
